/*
socket 错误包裹函数。
**/

#ifndef _WRAPFUNC_INCLUDED_
#define _WRAPFUNC_INCLUDED_
#include <sys/socket.h>
#include <unistd.h>
#include <sys/select.h>
#include <poll.h>
#include <fcntl.h>

int Socket(int family, int type, int protocol);
void Bind(int fd, const struct sockaddr *sa, socklen_t salen);
void Connect(int fd, const struct sockaddr *sa, socklen_t salen);
void Listen(int fd, int backlog);
int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr);
void Shutdown(int fd, int how);
int Select(int nfds, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout);
int Poll(struct pollfd *fds, nfds_t nfds, int timeout);

int Getpeername(int fd, struct sockaddr *sa, socklen_t *salenptr);

void Inet_pton(int af, const char *src, void *dst);
void Setsockopt(int fd, int level, int optname, const void *optvar, socklen_t optlen);

ssize_t Read(int fd, void *buf, size_t nbytes);
void Write(int fd, const void *buf, size_t nbytes);
void Close(int fd);

ssize_t Recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *sa, socklen_t *salenptr);
ssize_t Sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *sa, socklen_t salen);

pid_t Fork();
int Fcntl(int fd, int cmd, int arg);

int Tcp_connect(const char *host, const char *service);
int Tcp_listen(const char *host, const char *service, int *addrlenp);
int Udp_client(const char *host, const char *service, struct sockaddr **saptr, socklen_t *lenptr);
int Udp_connect(const char *host, const char *service);
int Udp_server(const char *host, const char *service, socklen_t *lenptr);

#endif // _WRAPFUNC_INCLUDED_
